<template>
    <span class="span2">我是首页</span>
</template>

<!-- js或ts -->
<script lang="ts">
export default {
    name: 'routeGuardTest1Home'
}
</script>

<!-- js或ts -->
<script setup lang="ts">
import { onBeforeRouteLeave } from 'vue-router'
//方法
//路由离开前
onBeforeRouteLeave((to, from, next) => {
    console.log('路由离开前')
    console.log('to：', to)
    console.log('from：', from)
    console.log('next：', next)
    if (confirm('我是组件路由离开前守卫，确定离开吗？')) {
        next();
    }
})
</script>

<!-- 样式 -->
<style scoped></style>